package wynb;

import com.foreknow.bean.User;
import com.foreknow.service.UserService;
import com.foreknow.service.impl.UserServiceImpl;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setForeground(Color.RED);
		setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Administrator\\Desktop\\\u6211\u7684\\\u7199\u5FC3\u5065\u5EB7\\img\\do7.png"));
		setTitle("\u767B\u5F55");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 776, 541);
		contentPane = new JPanel();
		contentPane.setBackground(Color.GREEN);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JButton btnNewButton = new JButton("\u767B\u5F55");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				System.out.println("login");
				//调用Service中的方法
				UserService service = new UserServiceImpl();
				//获取到输入框中的内容
				String adminName = textField.getText();
				String password = passwordField.getText();
//				System.out.println(adminName+"---"+password);
				User user = service.isValidate(adminName,password);
				System.out.println(user.getAdminName());
			}
		});
		btnNewButton.setBounds(41, 295, 318, 144);
		contentPane.add(btnNewButton);

		JLabel label = new JLabel("\u7528\u6237\u540D\uFF1A");
		label.setFont(new Font("宋体", Font.PLAIN, 41));
		label.setBounds(127, 59, 219, 69);
		contentPane.add(label);

		JLabel label_1 = new JLabel("\u5BC6\u7801\uFF1A");
		label_1.setFont(new Font("宋体", Font.PLAIN, 81));
		label_1.setBounds(48, 113, 289, 210);
		contentPane.add(label_1);

		textField = new JTextField();
		textField.setBounds(335, 75, 377, 48);
		contentPane.add(textField);
		textField.setColumns(10);

		passwordField = new JPasswordField();
		passwordField.setBounds(301, 181, 431, 88);
		contentPane.add(passwordField);

		JButton button = new JButton("\u53D6\u6D88");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("取消");
			}
		});
		button.setBounds(404, 292, 346, 151);
		contentPane.add(button);

		JButton btnNewButton_1 = new JButton("\u6CE8\u518C");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				UserService service = new UserServiceImpl();
				String adminName = textField.getText();
				String password = passwordField.getText();
				User user = new User();
				user.setAdminName(adminName);
				user.setPassword(password);
				service.addUser(user);
				System.out.println("ok");
			}
		});
		btnNewButton_1.setBounds(41, 457, 706, 38);
		contentPane.add(btnNewButton_1);
	}
}
